﻿using System;
using UnityEngine;

namespace MassiveBattle.Manager
{
	/// <summary>
	/// 공성전 기본 클래스.
	/// </summary>
	public class BaseWarfareManager : BaseManager
	{
		public override bool IsRaid
		{
			get { return false; }
		}

		protected override void InitPlayerPosition(GameObject member, int line, int pos, ref EArea area)
		{
			member.transform.position = formationPositionRoot.Find(string.Format("Player/{0}/{1:00}", line + 1, pos + 1)).position;
		}

		protected override void InitEnemy()
		{
			var sideData = DataList[ESide.ENEMY];

			for (int i = 0, j = 0; i < 3; i++)
			{
				for (int k = 0; k < 8 - i; k++, j++)
				{
					GameObject member = ArmyDeploy.deployedEnemyPawnList[j];

					if (member == null)
						continue;

					MemberModel memberData = FindMemberData(member.name);

					member.SetActive(true);
					member.transform.position = formationPositionRoot.Find(string.Format("Enemy/{0}/{1:00}", i + 1, k + 1)).position;

					var controller = member.AddComponent<Controller.MemberController>();

					sideData.CharacterList.Add(controller);

					controller.SetManager(this);
					controller.Init(memberData, ESide.ENEMY, (ELine)i, k, EArea.NONE);
				}
			}

			sideData.InitHealthPoint();
			sideData.UpdateHealthPoint();

			UI.NameEnemy = "Enemy";
			UI.SetPortraitEnemy(sideData.CharacterList[0]);
		}

		public override void StartBattle()
		{
			Init(100);
		}

		protected override void RequestBattleEnd(bool isWin)
		{
			UI.ShowBattleResult(Report);
		}
	}
}
